package org.jeecg.modules.parameter.biz.controlltr;


import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.parameter.api.dto.trains.SimAddTrainDto;
import org.jeecg.modules.parameter.api.entity.SimTrain;
import org.jeecg.modules.parameter.api.vo.assistance.SimAssJsonVo;
import org.jeecg.modules.parameter.api.vo.hall.SimHallVo;
import org.jeecg.modules.parameter.api.vo.trains.SimTrainVo;
import org.jeecg.modules.parameter.biz.service.SimLineTrainService;
import org.jeecg.modules.parameter.common.api.dto.PatchPO;
import org.jeecg.modules.parameter.common.utils.oConvertUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lsy
 * @date 2024/09/17
 */
@Api(tags = "参数管理-车辆管理")
@RestController
@RequestMapping(value = {"/lineTrainInfo"}, produces = {"application/json; charset=utf-8"})
@Slf4j
public class SimLineTrainController extends JeecgController<SimTrain, SimLineTrainService> {
    @Resource
    private SimLineTrainService simLineTrainService;


    @ApiOperation(value = "车辆管理-查询所有车辆信息", notes = "查询辅助设施")
    @PostMapping(value = "/getAllTrain")
    public Result<List<SimTrainVo>> getAssAndPoints(@RequestParam(name = "LineId", required = true) String id) {
        List<SimTrainVo> simTrainVo = oConvertUtils.entityListToModelList(simLineTrainService.getAllTrain(id), SimTrainVo.class);
        return Result.ok(simTrainVo);
    }

    @ApiOperation(value = "车辆管理-批量添加车辆", notes = "添加辅助设施")
    @PostMapping(value = "/addTrain")
    public Result<List<SimAssJsonVo>> addAssAndPoints(@RequestBody SimAddTrainDto simAddTrainDto) {


        for (int i = 0; i < simAddTrainDto.getNum(); i++) {
            SimTrain simTrain=oConvertUtils.entityToModel(simAddTrainDto,SimTrain.class);
            assert simTrain != null;
            simTrain.setBodyId(simTrain.getBodyId() + i);
            simTrain.setTrainName(simTrain.getTrainName() + i);
            simLineTrainService.save(simTrain);
        }
        return Result.ok("添加成功");
    }


    @ApiOperation(value = "车辆管理-修改车辆信息", notes = "修改车辆信息")
    @PostMapping(value = "/editTrain")
    public Result<Boolean> editTrain(@RequestBody PatchPO patchPo) {
        return Result.ok(simLineTrainService.updatePatch(patchPo));
    }

    @ApiOperation(value = "车辆管理-删除车辆", notes = "删除车辆")
    @DeleteMapping(value = "/deleteTrain")
    public Result<String> deleteTrain(@RequestParam(name = "id") String id) {
        simLineTrainService.removeById(id);
        return Result.ok("删除成功");
    }


}
